05 / 17

What is the purpose of action in form?

Role of the action Attribute in HTML Forms

The action attribute in an HTML <form> specifies the URL where the form data should be sent when the form is submitted. It defines the destination of the request.

Key Points About action
  1. 1

    It tells the browser which server endpoint should handle the submitted data.

  2. 2

    If omitted, the form submits to the current page URL by default.

  3. 3

    It can be an absolute URL (e.g., https://example.com/submit) or a relative URL (e.g., /submit).

  4. 4

    It works together with the method attribute (GET or POST) to define how and where the data is sent.

Example of action Usage
Difficulty: 2/10
Topics: form submission, action attribute, HTTP method

Scenario Questions

0-2 years experience
  1. 1

    If you create a simple contact form and leave out the action attribute, where does the browser send the data when the user clicks Submit?

  2. 2

    Show me the HTML you would write for a form that posts to /api/submit using the action attribute.

  3. 3

    What is the effect of setting action="" compared to omitting the attribute entirely?

2-5 years experience
  1. 1

    A login form suddenly started posting to the wrong endpoint after a refactor. How would you trace and fix the problem related to the action attribute?

  2. 2

    Explain why changing the action from "/login" to "/auth/login" broke submissions in a single‑page app that uses client‑side routing.

  3. 3

    When would you choose GET versus POST for a search form's action, and what are the trade‑offs?

5-8 years experience
  1. 1

    Our service needs to accept form submissions from several domains while preventing CSRF. How does the action attribute interact with CORS, and what mitigation strategies would you apply?

  2. 2

    Design a fallback for a form whose action URL might be temporarily unavailable, without relying on JavaScript. How would you handle retries or alternate endpoints?

  3. 3

    Discuss performance implications of pointing the action attribute at a serverless function versus a traditional monolith endpoint.

8+ years experience
  1. 1

    We are migrating legacy forms with hard‑coded action URLs to a micro‑frontend architecture. What migration plan would you propose to decouple the action from markup while preserving SEO and accessibility?

  2. 2

    How would you establish a company‑wide convention for form actions to ensure consistency, security, and observability across dozens of services?

  3. 3

    Multiple teams need to submit data to a central ingestion pipeline. How would you design the action‑URL strategy and supporting infrastructure to handle versioning and backward compatibility?

Follow-up Questions

  • Can you explain how the browser resolves a relative action URL?
  • What differences do you see when the action attribute is omitted versus set to an empty string?
  • How does the chosen HTTP method interact with the action attribute?